<?php
declare(strict_types=1);

namespace app\admin\controller\admin;

use think\facade\Request;
use think\facade\Db;
use app\common\service\GmEmail as S;
use app\common\model\GmEmail as M;
use app\common\model\AdminAdmin as A;
use think\facade\Session;

class GmEmail extends \app\admin\controller\Base
{

    //     // 
//     public function index(){
//          // 远程页面的 URL
//         $remoteUrl = 'http://'.$this->serverAddress.'/admin/preSendEmail.php'; 

    //         // 获取远程页面的内容
//         $htmlContent = file_get_contents($remoteUrl);

    //         // 设置响应头，指定返回的内容类型为 HTML
//         header('Content-Type: text/html');

    //         // 返回远程页面的内容
//         echo $htmlContent;
//     }


    //     public function goSH(){
//         // 远程页面的 URL
//        $remoteUrl = 'http://'.$this->serverAddress.'/admin/preExapage.php'; 

    //        // 获取远程页面的内容
//        $htmlContent = file_get_contents($remoteUrl);

    //        // 设置响应头，指定返回的内容类型为 HTML
//        header('Content-Type: text/html');

    //        // 返回远程页面的内容
//        echo $htmlContent;
//    }

    public function index()
    {
        $ipaddress = env('APP_DEBUG') ? config('web')['developmentServer'] : config('web')['productionServer'];
        $adminId = Session::get('admin.id');
        return $this->fetch('index', ['adminId' => $adminId, 'ipaddress' => $ipaddress]);
    }

    //框架物品发送
    public function index2()
    {
        $ipaddress = env('APP_DEBUG') ? config('web')['developmentServer'] : config('web')['productionServer'];
        $adminId = Session::get('admin.id');
        $items = A::getItemList();
        $serverList = A::getServerList();
        return $this->fetch('index2', ['adminId' => $adminId, 'ipaddress' => $ipaddress, 'items' => $items, 'serverList' => $serverList]);
    }

    //获取更新服务器列表
    public function getServerList(){
        $serverList = A::getServerList();
        if ($serverList == null) {return json(['code' => 201, 'msg' => "操作失败"]);}
        return json(['code' => 200, 'msg' => '操作成功', 'serverList' => $serverList]);
    }

    //根据玩家账号查找角色
    public function getPlayerById()
    {
        $adminId = Request::param('adminId');
        if ($adminId == null) {
            return json(['code' => 201, 'msg' => "admin is null"]);
        }
        $serverId = Request::param('serverId');
        if ($serverId == null) {
            return json(['code' => 201, 'msg' => "区服为空"]);
        }
        $playerId = Request::param('accountId');
        if ($playerId == null) {
            return json(['code' => 201, 'msg' => "账号为空"]);
        }

        $player = A::getPlayerById($serverId, $playerId);
        if ($player == null) {return json(['code' => 201, 'msg' => "角色不存在"]);}
        return json(['code' => 200, 'msg' => '操作成功', 'roleList' => $player]);
    }

    //充值/邮件
    public function recharge(){
        $adminId = Request::param('adminId');
        $type = Request::param('type');
        $playerId = Request::param('playerId');
        $serverId = Request::param('serverId');
        $playName = Request::param('playName');
        $chargeNum = Request::param('chargeNum');
        $chargeType = Request::param('chargeType');
        //非正常访问验证
        if ($adminId == null) {
            return json(['code' => 201, 'msg' => "admin is null"]);
        }
        // 验证参数是否为空
        if (empty($type) || empty($playerId) || empty($serverId) || empty($playName) || empty($chargeNum) || empty($chargeType)) {
            return json(['code' => 201, 'msg' => "parameter data error"]);
        }
        //执行充值

    }


    public function goSH()
    {
        $ipaddress = env('APP_DEBUG') ? config('web')['developmentServer'] : config('web')['productionServer'];
        return $this->fetch('go_s_h', ['ipaddress' => $ipaddress]);
    }

    public function spemail()
    {
        $ipaddress = env('APP_DEBUG') ? config('web')['developmentServer'] : config('web')['productionServer'];
        return $this->fetch('spemail', ['ipaddress' => $ipaddress]);
    }

}